home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5415 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  69 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: (void(far *)()) 0
  5. Date: Fri, 09 Feb 96 00:38:55 GMT
  6. Organization: none
  7. Message-ID: <823826335snz@genesis.demon.co.uk>
  8. References: <341998718.10858110@magnet.at> <31165B9D.398E@imsisoft.com> <4f66c0$cn0@solutions.solon.com> <3118F813.41BF@imsisoft.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3118F813.41BF@imsisoft.com>
  15.            vbazarov@imsisoft.com "Victor Bazarov" writes:
  16.  
  17. >Peter Seebach wrote:
  18. >> 
  19. >> In article <31165B9D.398E@imsisoft.com>,
  20. >> Victor Bazarov  <vbazarov@imsisoft.com> wrote:
  21. >> >> .... = (void(far *)()) 0;
  22. >> 
  23. >> >> Now I want to know if my assumption is right and
  24. >> >> in case it is, what does this mean for 0 ?
  25. >> 
  26. >> >Nothing but what you've said -- cast. '0' has type 'int',
  27. >> >and must be converted into pointer to function in order
  28. >> >to be properly assigned.
  29. >> 
  30. >> Not exactly.
  31. >> 
  32. >> 0 is a special case.  Zero cast to a pointer type is a null pointer of that
  33.  
  34. In fact an integral constant expression in a context that requires a pointer
  35. is implicitly converted to a null pointer of that type - no cast is required,
  36. e.g.
  37.  
  38. char *ptr = 0;
  39.  
  40. initialised ptr to the char * null pointer.
  41.  
  42. >> type.  Or rather, *a constant zero* is.  An integer with value zero may
  43. >> produce different results.
  44. >
  45. >As I undestood, this "may produce different results":
  46. >
  47. >typedef void (far *pVOIDVOID)();
  48. >int zero = 0;
  49. >pVOIDVOID funky;
  50. >funky = (void(far *)()) zero;
  51. >
  52. >than
  53. >
  54. >typedef void (far *pVOIDVOID)();
  55. >pVOIDVOID funky;
  56. >funky = (void(far *)()) 0;
  57. >
  58. >?
  59.  
  60. Exactly. The compiler can only perform the 'magic' if it sees 0 as the result
  61. of a constant expression at compile time. 0 is an integral constant expression
  62. whereas zero is not (even if it was defined as const int).
  63.  
  64. -- 
  65. -----------------------------------------
  66. Lawrence Kirby | fred@genesis.demon.co.uk
  67. Wilts, England | 70734.126@compuserve.com
  68. -----------------------------------------
  69.